// 条件查询；

const MongoClient = require('mongodb').MongoClient;
const url = 'mongodb://localhost:27017';
// const dbName = 'runoob';
const dbName = 'testmgdb';
const colName = 'userinfo';
//连接 
async function getConnect() {
    try {
        let connct = await MongoClient.connect(url, { useNewUrlParser: true });
        return connct;
    } catch (error) {
        throw error;
    }
}

// CRUD

async function exeFun() {
    let connect = await getConnect();
    let coll = connect.db(dbName).collection(colName);

    let res = await coll.updateOne({
        password: "111111"
    }, {
        // where: { name: '小小' }
        where: { _id: '60a71d75eea74e3a3489b473' }
    });
    return res;
}

exeFun().then(res => {
    console.log("update_res", JSON.stringify(res, null, 4));
}).catch(error => {
    console.log(error);
})




// { "_id": { "$oid": "60a71d75eea74e3a3489b473" }, "name ": "小不点", "password": "123456", "age": "18" }